{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "08d3f0c0-28b9-4902-9995-09edc8336383",
   "metadata": {},
   "source": [
    "# thepipe\n",
    "https://github.com/emcf/thepipe/tree/main"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "de9020f4-1d90-4623-bb66-5cd99ce3daad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thepipe_api                              0.3.6\n",
      "\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
      "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip list | grep thepipe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ff5bf528-7399-4158-9e0c-d6765b5fe5bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "from thepipe_api import thepipe"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "400bed97-18d1-4983-9ffd-379a93fa3a6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'text'"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chunks = thepipe.extract(\"../datasets/SWS-05-IT-11-2020-software.pdf\",local=True)\n",
    "\n",
    "# chunks[0]['content'][1]['image_url']['url']\n",
    "chunks[0]['content'][0]['type']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "25fa6148-dbd5-41b1-9ac5-888e4ec3e984",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'type': 'text', 'text': '../datasets/SWS-05-IT-11-2020-software.pdf:\\n```\\n                                 \\n内部 \\n软件源代码安全管理流程 \\n \\n目录 \\n1 \\n术语和定义 ............................................................... 2 \\n2 \\n流程图 ................................................................... 3 \\n2.1 \\n源代码受控流程图 ..................................................... 3 \\n2.2 \\n源代码拷贝流程图 ..................................................... 4 \\n3 \\n流程表述 ................................................................. 5 \\n3.1 \\n源代码受控流程表 ..................................................... 5 \\n3.2 \\n源代码拷贝流程表 ..................................................... 6 \\n4 \\n表单格式 ................................................................. 6 \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n\\n```\\n'}\n"
     ]
    },
    {
     "ename": "KeyError",
     "evalue": "0",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Input \u001b[0;32mIn [103]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      3\u001b[0m \u001b[38;5;28mprint\u001b[39m(content)\n\u001b[1;32m      4\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m0\u001b[39m,\u001b[38;5;28mlen\u001b[39m(content)):\n\u001b[1;32m      5\u001b[0m     \u001b[38;5;66;03m# print(content[0])\u001b[39;00m\n\u001b[0;32m----> 6\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mcontent\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtype\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m==\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtext\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m      7\u001b[0m         \u001b[38;5;28mprint\u001b[39m(content[i][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtext\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m      8\u001b[0m     \u001b[38;5;66;03m# if c['type'] =='image_url':\u001b[39;00m\n\u001b[1;32m      9\u001b[0m     \u001b[38;5;66;03m#     print(c['image_url'])\u001b[39;00m\n",
      "\u001b[0;31mKeyError\u001b[0m: 0"
     ]
    }
   ],
   "source": [
    "for chunk in chunks:\n",
    "    for content in chunk['content']:\n",
    "        print(content)\n",
    "        for i in range(0,len(content)):\n",
    "            # print(content[0])\n",
    "            if content[i]['type'] =='text':\n",
    "                print(content[i]['text'])\n",
    "            # if c['type'] =='image_url':\n",
    "            #     print(c['image_url'])\n",
    "            print(i)\n",
    "        # print(content['text'])\n",
    "        # print(content)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "744850e9-03bf-4ed2-a869-a2c122d3e1c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
